#!/bin/bash
#每个节点都设置
# haproxy高可用代理mariadb
echo '#mariadb_cluster
listen mariadb_cluster
  mode tcp     
  bind controller:3306     
  balance leastconn     
  option mysql-check user haproxy     
  server controller1 controller1:3306 weight 1 check inter 2000 rise 2 fall 5     
  server controller2 controller2:3306 weight 1 check inter 2000 rise 2 fall 5
  server controller3 controller3:3306 weight 1 check inter 2000 rise 2 fall 5
'>>/etc/haproxy/haproxy.cfg
systemctl restart haproxy.service
echo "waiting for haproxy ready"
sleep 10
#测试
DBPass=innobase
mysql -h controller -u root -p$DBPass -e "show status like 'wsrep_cluster_size';"